/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.pucp.Ventas.Vista;

import java.awt.event.ActionListener;
import java.awt.event.KeyListener;
import java.util.ArrayList;
import javax.swing.JFrame;
import pe.edu.pucp.Modelo.Cliente;
import pe.edu.pucp.Modelo.EstadoCliente;
import pe.edu.pucp.Modelo.TipoCliente;
import pe.edu.pucp.Modelo.TipoCorreo;
import pe.edu.pucp.Modelo.TipoDocumento;
import pe.edu.pucp.Util.ValHelper;

/**
 *
 * @author katy
 */
public class ClienteGUI extends javax.swing.JDialog {

    /**
     * Creates new form ClienteGUI
     */

    
    public ClienteGUI (JFrame parent, boolean modal) {
       
        super(parent, modal);
        initComponents();
        setLocationRelativeTo(null);
        this.txtNumDoc.setTransferHandler(null);
        this.txtApellidoMaterno.setTransferHandler(null);
        this.txtApellidoPaterno.setTransferHandler(null);
        this.txtNombres.setTransferHandler(null);
        this.txtRazon.setTransferHandler(null);
        this.txtCorreo.setTransferHandler(null);
    }
    
    public void setValues(Cliente c) {
    
        if(c.getTipoCliente().getDescripcion().toUpperCase().equals("EMPRESA")) {
            txtRazon.setText(c.getNombre());
        } else {
            txtNombres.setText(c.getNombre());
            txtApellidoPaterno.setText(c.getAppaterno());
            txtApellidoMaterno.setText(c.getApmaterno());
        }
            
        txtNumDoc.setText(c.getNumdoc());
        cmbTipoDoc.setSelectedItem(c.getTipoDocumento());
        cmbEstado.setSelectedItem(c.getEstadoCliente());
        txtCorreo.setText(c.getCorreo());
    }
    
    public void setEstadoGuardar( String titulo){        
        this.setTitle("SIGEPA - "+titulo);
    }
    public void setEnabledNombreApellidosTxt(boolean b) {
        txtApellidoMaterno.setEnabled(b);
        txtApellidoPaterno.setEnabled(b);
        txtNombres.setEnabled(b);
    }
    
    public void setEnabledRazonSocialTxt(boolean b) {
        txtRazon.setEnabled(b);
    }
    
    public void setEnabledTipoClienteCmb(boolean b) {
        cmbTipoCliente.setEnabled(b);
    }
    
    public String getRazonSocial() {
        return txtRazon.getText();
    }
    
    public int getTipoCliente() {
        return cmbTipoCliente.getSelectedIndex();
    }
    
    public int getTipoCorreo() {
        return cmbTipoCorreo.getSelectedIndex();
    }
    
    public int getTipoDocumento() {
        return cmbTipoDoc.getSelectedIndex();
    }
    
    public int getEstado()
    {
        return cmbEstado.getSelectedIndex();
    }
    
    public String getNombre() {
        return txtNombres.getText();
    }
    
    public String getApellidoPaterno(){
        return txtApellidoPaterno.getText();
    }
    
    public String getApellidoMaterno(){
        return txtApellidoMaterno.getText();
    }
    
    public String getCorreo() {
        return txtCorreo.getText();
    }
    
    public String getNumeroDoc() {
        return txtNumDoc.getText();
    }
    
    public void addTipoClienteCmbListener(ActionListener listener) {
        cmbTipoCliente.addActionListener(listener);
    }
    
    public void addGuardarButtonListener(ActionListener listener){
      
       btnGuardar.addActionListener(listener);
    }
    
    public void addCancelButtonListener(ActionListener listener) {
        this.btnCancelar.addActionListener(listener);
    }
    
    public void addSoloNumerosListener(KeyListener listener) {
        this.txtNumDoc.addKeyListener(listener);
    }
    
    public void addSoloTextoListener (KeyListener listener) {
        this.txtApellidoMaterno.addKeyListener(listener);
        this.txtApellidoPaterno.addKeyListener(listener);
        this.txtNombres.addKeyListener(listener);
        this.txtRazon.addKeyListener(listener);
        this.txtCorreo.addKeyListener(listener);
    }
    
    public void llenaTipoCliente(ArrayList<TipoCliente> lst, Cliente c) {
      int defaultIndex = 0;
      if(lst != null)
      {
          for (int i = 0; i < lst.size(); i++)
          {
              TipoCliente t = lst.get(i);
              if((c != null) && (c.getTipoCliente().getIdtipo() == t.getIdtipo()))
                  defaultIndex = i;
              cmbTipoCliente.addItem(t.getDescripcion());
          }
      }  
      cmbTipoCliente.setSelectedIndex(defaultIndex);
    }
    
    public void llenaTipoDocs(ArrayList<TipoDocumento> lst, Cliente c) {
      int defaultIndex = 0; 
      if(lst != null)
      {
        for (int i = 0; i < lst.size(); i++)
        {
            TipoDocumento t = lst.get(i);
            if((c != null) && (c.getTipoDocumento().getIdtipodoc() == t.getIdtipodoc()))
                defaultIndex = i;
            cmbTipoDoc.addItem(t.getDescripcion());
        }
      }
      cmbTipoDoc.setSelectedIndex(defaultIndex);
    }
    
     public void llenaEstadosCliente(ArrayList<EstadoCliente> lst, Cliente c) {
      int  defaultIndex = 0;
      if(lst != null)
      {
          for (int i = 0; i < lst.size(); i++)
          {
              EstadoCliente t = lst.get(i);
              if ((c!= null)&&(c.getEstadoCliente().getIdestado() == t.getIdestado()))
                  defaultIndex = i;
              else
                  if ((t.getDescripcion().toUpperCase().equals("ACTIVO")))
                      defaultIndex = i;
                  
              cmbEstado.addItem(t.getDescripcion());
          }
      }
      cmbEstado.setSelectedIndex(defaultIndex);
    }

     public void llenaTipoCorreo(ArrayList<TipoCorreo> lst, Cliente c) {
    int defaultIndex = 0; 
      if(lst != null)
      {
        for (int i = 0; i < lst.size(); i++)
        {
            TipoCorreo t = lst.get(i);
            if((c != null) && (c.getTipoCorreo().getIdtipocorreo() == t.getIdtipocorreo()))
                defaultIndex = i;
            cmbTipoCorreo.addItem(t.getExtension());
        }
      }
      cmbTipoCorreo.setSelectedIndex(defaultIndex);
     }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        btnGuardar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        txtNombres = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        cmbTipoDoc = new javax.swing.JComboBox();
        txtNumDoc = new javax.swing.JTextField();
        txtCorreo = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        cmbEstado = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        txtApellidoPaterno = new javax.swing.JTextField();
        txtApellidoMaterno = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        cmbTipoCorreo = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        cmbTipoCliente = new javax.swing.JComboBox();
        txtRazon = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(702, 290));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos"));

        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/checkmark.png"))); // NOI18N

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/delete.png"))); // NOI18N

        jLabel1.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jLabel1.setForeground(java.awt.Color.gray);
        jLabel1.setText("Nombres:");

        jLabel2.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jLabel2.setForeground(java.awt.Color.gray);
        jLabel2.setText("Tipo Documento:");

        jLabel4.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jLabel4.setForeground(java.awt.Color.gray);
        jLabel4.setText("Correo electrónico :");

        jLabel5.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jLabel5.setForeground(java.awt.Color.gray);
        jLabel5.setText("Estado :");

        cmbEstado.setEnabled(false);

        jLabel6.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jLabel6.setForeground(java.awt.Color.gray);
        jLabel6.setText("Apellido Paterno: ");

        jLabel7.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jLabel7.setForeground(java.awt.Color.gray);
        jLabel7.setText("Apellido Materno: ");

        jLabel9.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jLabel9.setForeground(java.awt.Color.gray);
        jLabel9.setText("Tipo Cliente: ");

        jLabel10.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jLabel10.setForeground(java.awt.Color.gray);
        jLabel10.setText("Razón Social :");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addComponent(jLabel2)
                    .addComponent(jLabel10)
                    .addComponent(jLabel1)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtApellidoMaterno)
                    .addComponent(cmbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 234, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtApellidoPaterno)
                    .addComponent(txtNombres, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(cmbTipoCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 313, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(txtCorreo, javax.swing.GroupLayout.PREFERRED_SIZE, 234, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmbTipoCorreo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(txtRazon, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cmbTipoDoc, javax.swing.GroupLayout.Alignment.LEADING, 0, 234, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtNumDoc, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(75, 75, 75))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(546, 546, 546)
                .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmbTipoCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(cmbTipoDoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNumDoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(txtRazon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtNombres, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtApellidoPaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtApellidoMaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtCorreo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(cmbTipoCorreo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cmbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 670, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 339, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JComboBox cmbEstado;
    private javax.swing.JComboBox cmbTipoCliente;
    private javax.swing.JComboBox cmbTipoCorreo;
    private javax.swing.JComboBox cmbTipoDoc;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField txtApellidoMaterno;
    private javax.swing.JTextField txtApellidoPaterno;
    private javax.swing.JTextField txtCorreo;
    private javax.swing.JTextField txtNombres;
    private javax.swing.JTextField txtNumDoc;
    private javax.swing.JTextField txtRazon;
    // End of variables declaration//GEN-END:variables
}
